﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
using DataBaseNew;

namespace Common.DataBaseNew
{
    class InitData
    {
        static void Main(string[] args)
        {
            SQLInit sql_init = new SQLInit();
            DBmediator db = new DBmediator();

            db = sql_init.initDataBase(db);
            
            
            
            
            //מנהל על
            User Gilad = db.getDirector();
            //מנהל
            User Ilya = new User("Ilya", "Sonin", "Sonini", "111", "bla1@bla.com");
        //    db.addForum("Forum1", Ilya); //id = 1
            
            db.addSubForum(1, "Games");  //id = 1
            db.addSubForum(1, "Movies"); //id = 2
            db.addSubForumModerator(1, 1, "Ilya");
            db.registerUser(1, "Natalya", "Safro", "Natali", "100", "bla2@bla.com");
            User Natalya = db.getUser(1, "Natalya");
            db.addSubForumModerator(1, 2, "Natalya");
            User Moti = new User("Moti", "Moti", "Elishay ", "222", "bla3@bla.com");
            User Zach = new User("Zach", "Zach", "Laniado", "333", "bla4@bla.com");
            db.registerUser(1, Moti);
            db.registerUser(1, Zach);



            db.addThread(1, 1, "Fifa", "Sport game", Ilya);  // id = 1
            db.addThread(1, 1, "IgI", "Computer game", Natalya);  //id = 2
            db.addThread(1, 2, "Titanic", "Boring movie", Moti); //id = 1
            db.addThread(1, 2, "Matrix", "Owsom movie!!!", Zach); //id = 2

            db.addPost(1, 1, 1, "Love it", "Very good game...", Gilad);
            db.addPost(1, 1, 1, "Hate it", "Very bad game...", Ilya);
            db.addPost(1, 1, 2, "nice game", "Very good game...", Natalya);
            db.addPost(1, 1, 2, "fichsa game", "Very bad game...", Moti);
            db.addPost(1, 2, 1, "Love it", "Very good movie...", Zach);
            db.addPost(1, 2, 2, "Hate it", "Very bad movie...", Gilad);

            /*
                Console.WriteLine(db.getForum(1).getTitle().Equals("Forum1"));
                Console.WriteLine(db.getDirector().getUserName().Equals("Gilad"));
                Console.WriteLine(db.containsUser(1, "Gilad"));
                Console.WriteLine(db.containsUser(1, "Ilya"));
                Console.WriteLine(db.containsUser(1, "Natalya"));
                Console.WriteLine(db.containsUser(1, "Moti"));
                Console.WriteLine(db.containsUser(1, "Zach"));
                Console.WriteLine(db.getForumAdmin(1).getUserName().Equals("Ilya"));
                Console.WriteLine(db.isSubForumModerator(1, 1, "Ilya"));
                Console.WriteLine(db.isSubForumModerator(1, 1, "Gilad"));  //false
                Console.WriteLine(db.isSubForumModerator(1, 2, "Natalya"));
                Console.WriteLine(db.isSubForumModerator(1, 1, Ilya));
                Console.WriteLine(db.isSubForumModerator(1, 2, Natalya));

                Console.WriteLine();
                Console.WriteLine(db.getForum(1).getTitle());
                Console.WriteLine(db.dataBasetoString().ElementAt(0).Key);
                Console.WriteLine(db.dataBasetoString().ElementAt(0).Value);
                Console.WriteLine(db.dataBasetoString().Count);
                Console.WriteLine();

                Console.WriteLine(db.forumToString(1).ElementAt(0).Key);
                Console.WriteLine(db.forumToString(1).ElementAt(0).Value);
                Console.WriteLine(db.forumToString(1).ElementAt(1).Key);
                Console.WriteLine(db.forumToString(1).ElementAt(1).Value);
                Console.WriteLine(db.forumToString(1).Count);
                Console.WriteLine();

                Console.WriteLine(db.subForumToString(1, 1).ElementAt(0).Value);
                Console.WriteLine(db.subForumToString(1, 1).ElementAt(1).Value);
                Console.WriteLine(db.subForumToString(1, 2).ElementAt(0).Value);
                Console.WriteLine(db.subForumToString(1, 2).ElementAt(1).Value);
                Console.WriteLine();

                Console.WriteLine(db.threadToString(1, 1, 1).ElementAt(0).Value);
                Console.WriteLine(db.threadToString(1, 1, 1).ElementAt(1).Value);
                Console.WriteLine(db.threadToString(1, 1, 1).ElementAt(2).Value);
                Console.WriteLine();

                Console.WriteLine(db.threadToString(1, 1, 2).ElementAt(0).Value);
                Console.WriteLine(db.threadToString(1, 1, 2).ElementAt(1).Value);
                Console.WriteLine(db.threadToString(1, 1, 2).ElementAt(2).Value);
                Console.WriteLine();

                Console.WriteLine(db.threadToString(1, 2, 1).ElementAt(0).Value);
                Console.WriteLine(db.threadToString(1, 2, 1).ElementAt(1).Value);
                Console.WriteLine();

                Console.WriteLine(db.threadToString(1, 2, 2).ElementAt(0).Value);
                Console.WriteLine(db.threadToString(1, 2, 2).ElementAt(1).Value);
                Console.WriteLine();

                db.complaint(1, 1, "Ilya");
                db.complaint(1, 2, "Natalya");
                db.complaint(1, 1, "Ilya");
                db.complaint(1, 2, "Natalya");
                db.complaint(1, 1, "Ilya");
                db.complaint(1, 2, "Natalya");
                db.complaint(1, 1, "Ilya");
                db.complaint(1, 2, "Natalya");
                db.complaint(1, 1, "Ilya");
                db.complaint(1, 2, "Natalya");
                db.complaint(1, 1, "Ilya");
                db.complaint(1, 2, "Natalya");


                Console.WriteLine(db.getModeratorComplaints(1, 1, Ilya));
                Console.WriteLine(db.getModeratorComplaints(1, 2, Natalya));
                Console.WriteLine(db.getModeratorComplaints(1, 1, "Ilya"));
                Console.WriteLine(db.getModeratorComplaints(1, 2, "Natalya"));

                Console.WriteLine(db.isSubForumModerator(1, 1, "Ilya"));
                Console.WriteLine(db.isSubForumModerator(1, 2, "Natalya"));

                Console.WriteLine(db.removeSubForum(1, 1));

                DateTime d2 = DateTime.Today;
                Console.WriteLine(d1);
                Console.WriteLine(d2);
                Console.WriteLine((d1 - d2).Minutes);

            */


            
            /*         sql_init.addDataBase(1, "Gilad");    
                       sql_init.addForum("Forum1", 1, "Ilya", "Ilya", "Sonini", "111", "bla1@bla.com");
                       sql_init.addSubForum(1, "Games", 1, "Ilya");
                       sql_init.addSubForum(2, "Movies", 1, "Ilya");    
                       sql_init.registerUser(1, "Natalya", "Safro", "Natali", "100", "bla2@bla.com");
                       sql_init.addSubForumModerator(1, 2, "Natalya");
                       sql_init.registerUser(1, "Moti", "Moti", "Elishay ", "222", "bla3@bla.com");
                       sql_init.registerUser(1, "Zach", "Zach", "Laniado", "333", "bla4@bla.com");

            sql_init.addThread(1, 1, 1, "Fifa", "Sport game", "Ilya");
            sql_init.addThread(2, 1, 1, "IgI", "Computer game", "Natalya");
            sql_init.addThread(1, 1, 2, "Titanic", "Boring movie", "Moti");
            sql_init.addThread(2, 1, 2, "Matrix", "Owsom movie!!!", "Zach");
            sql_init.addPost(1, 1, 1, 1, "Love it", "Very good game...", "Gilad");
            sql_init.addPost(2, 1, 1, 1, "Hate it", "Very bad game...", "Ilya");
            sql_init.addPost(1, 1, 1, 2, "nice game", "Very good game...", "Natalya");
            sql_init.addPost(2, 1, 1, 2, "fichsa game", "Very bad game...", "Moti");
            sql_init.addPost(1, 1, 2, 1, "Love it", "Very good movie...", "Zach");
            sql_init.addPost(1, 1, 2, 2, "Hate it", "Very bad movie...", "Gilad");
            
            sql_init.updateDBIdforForums(1); 
            sql_init.updateFIdforSubForums(1, 2);  
            sql_init.updateSFidForThreads(1, 1, 2);
            sql_init.updateSFidForThreads(1, 2, 2);
            sql_init.updateTIdForPosts(1, 1, 1, 2);
            sql_init.updateTIdForPosts(1, 1, 2, 2);
            sql_init.updateTIdForPosts(1, 2, 1, 1);
            sql_init.updateTIdForPosts(1, 2, 2, 1);
 
           */

            sql_init.read();


            Console.WriteLine("End");
            Console.Read();
               

          //  return db;
        }
    }

}